package pl.un4giv3n.mightvsmagic.utils.display;

import java.util.Locale;

import javax.servlet.jsp.PageContext;

import org.displaytag.decorator.TableDecorator;
import org.displaytag.model.TableModel;

import pl.un4giv3n.mightvsmagic.entity.ItemStub;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.LocaleProvider;

public class DisplayItemStubDecorator extends TableDecorator implements
		LocaleProvider {

//	private TextProvider resourceBundle;

	@Override
	public void init(PageContext pageContext, Object decorated,
			TableModel tableModel) {
		super.init(pageContext, decorated, tableModel);
//		this.resourceBundle = new TextProviderFactory().createInstance(
//				getClass(), this);

	}

	
	public String getImg(){
		ItemStub item = (ItemStub) getCurrentRowObject();
		StringBuilder builder = new StringBuilder();
		builder.append(item.getName()).append("<br/>");
		builder.append("<img src='").append(item.getImgUrl()).append("' />");
		return builder.toString();
	}

	@Override
	public Locale getLocale() {
		ActionContext ctx = ActionContext.getContext();
		if (ctx != null) {
			return ctx.getLocale();
		} else {
			return Locale.getDefault();
		}
	}
}
